<?php

class Ead_Form_Curso extends Zend_Form
{

    public function init() {
   	    
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        
        $id = $front->getRequest()->getParam('id', 0);
        
        $this->setName('form_'.$controller);

        $el = new Zend_Form_Element_Hidden('CUR_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        $obj = new Ead_Model_DbTable_Catcurso();
        $row = $obj->fetchAll()->toArray();
        $arr = array();
        foreach($row as $r) $arr[$r['CTC_ID']] = $r['CTC_NOM']; 
        /*
        $el = new Zend_Form_Element_Select('CTC_ID',array('onchange' => ''));
        $el->setLabel('Categoria')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty')
        ->addMultiOptions($arr);
        $this->addElement($el);
         */
        $arr_set = array();
        if($id > 0){ // 1,2,3,
            $obj = new Ead_Model_DbTable_Cursocat();
            $row = $obj->fetchAll('CUR_ID = '.(int)$id);
            foreach($row as $ro) $arr_set[$ro['CTC_ID']] = $ro['CTC_ID'];  
        } 
        
        $el = new Zend_Form_Element_MultiCheckbox('CTC_IDLST');
        $el->setLabel('Categorias')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty')
        ->addMultiOptions($arr)
        ->setValue($arr_set);
        $this->addElement($el);
                
        
        $el = new Zend_Form_Element_Text('CUR_NOM');
        $el->setLabel('Nome')
                ->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Textarea('CUR_APR');
        $el->setLabel('Apresentação')
                //->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->setAttrib('cols', '90')->setAttrib('rows', '8')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Textarea('CUR_DSC');
        $el->setLabel('Descrição')
                //->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->setAttrib('cols', '90')->setAttrib('rows', '8')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        
        /*
        $img = 'public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'.*';
        foreach (glob($img) as $src) {
            $el = new Zend_Form_Element('img',array( 'helper'=>'formNote', 'value'=>'<img height="200" src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        $el = new Zend_Form_Element_File('CUR_FILE');
        $el->setLabel('Imagem Detalhe - Tamanho: 300x250')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
        */
        
        $img = 'public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'_p.*';
        foreach (glob($img) as $src) {
            $el = new Zend_Form_Element('img2',array( 'helper'=>'formNote', 'value'=>'<img height="200" src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }        
        $el = new Zend_Form_Element_File('CUR_FILE2');
        $el->setLabel('Imagem Listagem - Tamanho: 270x120')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
        
        
        $img = 'public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'_iconp.*';
        foreach (glob($img) as $src) {
            $el = new Zend_Form_Element('img3',array( 'helper'=>'formNote', 'value'=>'<img height="59" src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }        
        $el = new Zend_Form_Element_File('CUR_FILE3');
        $el->setLabel('Imagem Listagem - Tamanho: 59x59')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_DUR');
        $el->setLabel('Carga Horária - Horas')
            ->setRequired(true)
            ->addFilter('Int')
            ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_DURMIN');
        $el->setLabel('Carga Horária - Minutos')
            ->setRequired(true)
            ->addFilter('Int')
            ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_MAT');
        $el->setLabel('Material')
                //->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_SML');
        $el->setLabel('Simulado')
                //->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_PROF');
        $el->setLabel('Professor')
                //->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_QTDDIAACE',array());
        $el->setLabel('Dias Validade - Acesso Aluno ao Curso')
                ->addValidator('NotEmpty')
                ->setAttrib('class', 'numero')->setAttrib('maxLength', 3);
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_VLR',array('class'=>'valor'));
        $el->setLabel('Valor')
                ->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        
        $obj = new Ead_Model_DbTable_Formaspagamento();
        $row = $obj->fetchAll()->toArray();
        $arr = array();
        foreach($row as $r) $arr[$r['FOR_ID']] = $r['FOR_NOM']; 
        
        
        $obj = new Ead_Model_DbTable_Cursoforma();
        $row = $obj->fetchAll('CUR_ID = '.(int)$id);
        $arr_set = array();
        foreach($row as $r) $arr_set[$r['FOR_ID']] = $r['FOR_ID']; 
        
        $el = new Zend_Form_Element_MultiCheckbox('FOR_ID',array());
        $el->setLabel('Formas de Pagamento')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty')
        ->addMultiOptions($arr)
        ->setValue($arr_set);
        $this->addElement($el);
      
        
        $el = new Zend_Form_Element_Text('CUR_VES',array('class'=>'numero'));
        $el->setLabel('Cheque: Quantidade de Vezes')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_POR',array('class'=>'valor'));
        $el->setLabel('Depósito: Porcentagem de desconto')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
         $el = new Zend_Form_Element_Text('CUR_PROM',array('class'=>'valor'));
        $el->setLabel('Promoção')
                ->addFilters(array('StripTags','StringTrim'))
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('CUR_PROMDAT',array('class'=>'valor'));
        $el->setLabel('Data de Validade da Promoção')
                ->addValidator('NotEmpty');
        $el->setAttrib('class', 'data');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Checkbox('CUR_STAPROM',array('checked'=>'checked'));
        $el->setLabel('Produto em Destaque(Ativo/Desativo)')
            ->setRequired(true)
            ->addValidator('NotEmpty');
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Checkbox('CUR_STA',array('checked'=>'checked'));
        $el->setLabel('Status de Curso(Ativo/Desativo)')
            ->setRequired(true)
            ->addValidator('NotEmpty');
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Text('CUR_VLD');
        $el->setLabel('Visivel para venda até')
                //->setRequired(true)
                //->addFilter('StripTags')
                //->addFilter('StringTrim')
                ->addValidator('NotEmpty');
        $el->setAttrib('class', 'data');
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Text('CUR_ORD',array('class'=>'numero'));
        $el->setLabel('Ordem de listagem')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        
        $btn = new Zend_Form_Element_Submit('submit',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setLabel('Gravar');
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-button btn-ok');
        $this->addElement($btn);
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-button btn-cancel">Cancelar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-button btn-cancel');
        $this->addElement($btn);
        
        
    }

}